Programming iOS 10 by Matt Neuburg

Programming iOS 10 by Matt Neuburg

Author:Matt Neuburg
Language: eng
Format: epub
Publisher: O'Reilly Media
Published: 2016-11-25T05:00:00+00:00


Deal with the table’s appearance. If we deleted the section array, we’ll call deleteSections (and reload the section index if there is one); otherwise, we’ll call deleteRows.

That’s the strategy; here’s the implementation:

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt ip: IndexPath) { self.cellData[ip.section].remove(at:ip.row) if self.cellData[ip.section].count == 0 { self.cellData.remove(at:ip.section) self.sectionNames.remove(at:ip.section) tableView.deleteSections( IndexSet(integer: ip.section), with:.automatic) tableView.reloadSectionIndexTitles() } else { tableView.deleteRows(at:[ip], with:.automatic) } }

The user can also delete a row by sliding it to the left to show its Delete button without having explicitly entered edit mode; no other row is editable, and no other editing controls are shown. This feature is implemented “for free” by virtue of our having supplied an implementation of tableView(_:commit:forRowAt:).

If you’re like me, your first response will be: “Thanks for the free functionality, Apple, and now how do I turn this off?” Because the Edit button is already using the UIViewController’s isEditing property to track edit mode, we can take advantage of this and refuse to let any cells be edited unless the view controller is in edit mode:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.